/*!
 * @file Color.cpp
 * @author naoki takeda
 * @version 1.0
 */
#include "StdAfx.h"
#include "NTEngine/Math/Color.h"

namespace NTEngine
{
namespace Math
{

const Color COLOR_WHITE(1.F, 1.F, 1.F, 1.F);
static const float COLOR_T = 1.F / 255.F;

Color::Color(float alpha, float red, float green, float blue)
: a(alpha), r(red), g(green), b(blue)
{
}

Color::Color(Color32 c)
{
	operator=(c);
}

Color::Color(const Color& c)
: a(c.a), r(c.r), g(c.g), b(c.b)
{
}

void Color::operator=(const Color& c)
{
	a = c.a;
	b = c.r;
	g = c.g;
	b = c.b;
}

void Color::operator=(Color32 c)
{
	a = ((c & 0xFF000000) >> 24) * COLOR_T;
	r = ((c & 0x00FF0000) >> 16) * COLOR_T;
	g = ((c & 0x0000FF00) >> 8) * COLOR_T;
	b = (c & 0x000000FF) * COLOR_T;
}

Color::operator Color32() const
{
	return ((static_cast<Color32>(a * 255.F) << 24) |
		(static_cast<Color32>(r * 255.F) << 16) |
		(static_cast<Color32>(g * 255.F) << 8) |
		(static_cast<Color32>(b * 255.F)));
}

Color::operator const float*() const {
	return &r;
}

void Color::set(float alpha, float red, float green, float blue)
{
	a = alpha;
	r = red;
	g = green;
	b = blue;
}

void Color::set(Byte alpha, Byte red, Byte green, Byte blue)
{
	a = static_cast<float>(alpha) * COLOR_T;
	r = static_cast<float>(red) * COLOR_T;
	g = static_cast<float>(green) * COLOR_T;
	b = static_cast<float>(blue) * COLOR_T;
}

} // namespace Math
} // namespace NTEngine
// EOF